package com.bys.ots.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bys.ots.model.VSoInfo;
import com.bys.ots.pojo.Result;
import com.bys.ots.pojo.ResultUtil;
import com.bys.ots.service.ISoInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping(value = "/v3")
@Api(value = "VOrder Table Controller")
public class VOrderController {
    @Autowired
    private ISoInfoService soInfoService;

    private final Logger logger = LoggerFactory.getLogger(VOrderController.class);

    @ResponseBody
    @PostMapping(value = "/getVSoInfoList")
    @ApiOperation(value = "get SoInfoList")
    @ApiImplicitParams
            ({
                    @ApiImplicitParam(name = "email", paramType = "get", value = "请求体", required = true, defaultValue = "{email:\"\"}")
            })
    public List<VSoInfo> getVSoInfoList(@RequestBody(required = false) String str) {
        logger.info(
                "->User start to enter controller /getVSoInfoList, the email info is：email:{}",
                str);
        str = str.replace("%40", "@");
        String[] split = str.split("&");
        String email = null;
        String so = null;
        if (split[0].length() > 6) {
            email = split[0].substring(6);
        }
        if (split[1].length() > 3) {
            so = split[1].substring(3);
        }

        List<VSoInfo> infoList = soInfoService.getVSoInfoList(so,email);
        return infoList;
    }

    @GetMapping(value = "/getVSoInfoPage")
    @ApiOperation(value = "get SoInfo")
    @ApiImplicitParams
            ({
                    @ApiImplicitParam(name = "email", paramType = "get", value = "请求体", required = true, defaultValue = "{email:\"\"}")
            })
    public String getVSoInfoPage() {
        return "vOrderAll";
    }

    @GetMapping(value = "/getVSoLogisticInfo")
    @ApiOperation(value = "get VSoLogistic Info")
    @ApiImplicitParams
            ({

                    @ApiImplicitParam(name = "type", value = "订单类型", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "so", value = "so编号", required = true, dataType = "String")
            })
    public Result getVSoLogisticInfo(@RequestParam String type, @RequestParam String so) {
        logger.info(
                "->User start to enter controller  /getVSoLogisticInfo, the request info is： type:{}, so:{}",
                type, so);
        return soInfoService.getSoLogisticInfo(type, so);
    }
}
